package cn.itsource.controller;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/findUser/{id}")
    @HystrixCommand(fallbackMethod = "fallbackMethod")
    public User findUser(@PathVariable("id")Long id){
        String url = "http://USER-SERVER/user/findOne/"+id;
        return restTemplate.getForObject(url,User.class);
    }
    //托底方法
    public User fallbackMethod(@PathVariable("id")Long id){
        //返回托底数据,友好的提示信息
        return new User(-1L ,"用户服务不可用，执行托底方法",-1);
    }
}
